<template>
	<view class="auth">
		<view class="btn" @click="handleLogin">
			<button type="primary">微信授权登录</button>
		</view>
		<view class="agreement">
			登录即代表您同意用户<text>用户协议</text>和<text>隐私协议</text>
		</view>
	</view>
</template>

<script>
	import {wxLogin} from '@/request/auth.js'
	export default {
		data() {
			return {

			}
		},
		methods: {
			handleLogin(){
				uni.getUserProfile({
					desc:"获取信息",
					success:async (res)=>{
						console.log(res)
						let reslut = await wxLogin({
							openid:uni.getStorageSync('openid'),
							iv:res.iv,
							rawData:res.rawData,
							signature:res.signature,
							encryptedData:res.encryptedData
						})
		     console.log(reslut)
			 let token = `Bearer ` + reslut.data.data.token
			 // console.log(token)
			 uni.setStorageSync('token',token)
			 uni.navigateBack({
			 	delta:-1
			 })
					},
					fail(err) {
						uni.showToast({
							title:'您已取消授权'
						})
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.auth{
		padding: 30rpx;
	}
.btn{
	margin-top: 200rpx;
	// padding: 30rpx;
}
.agreement{
	margin-top: 60rpx;
	color: #cbcbcb;
	font-size: 30rpx;
	text{
		color: #0b76de;
	}
}
</style>
